﻿using MIMSDomain.Abstract;
using MIMSDomain.Concrete;
using MIMSDomain.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MIMSDomain.Concrete
{
    public class EFDrugHistoryRepository : IRepository<DrugHistory>, IDisposable
    {
        EFDbContext dbContext = new EFDbContext();

        public IQueryable<DrugHistory> All
        {
            get { 
                return dbContext.DrugHistories; 
            }
        }

        public bool Save(DrugHistory _T)
        {
            try
            {
                if (_T.Id == 0)
                {
                    dbContext.DrugHistories.Add(_T);
                    dbContext.SaveChanges();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception Ex)
            {
                //Log Exception
                throw new Exception(Ex.Message);
            }
            finally
            {
                //clean ups
            }
        }

        public DrugHistory GetById(int Id)
        {
            throw new NotImplementedException();
        }

        public IQueryable<DrugHistory> Search(System.Linq.Expressions.Expression<Func<DrugHistory, bool>> predicate)
        {
            return dbContext.DrugHistories.Where(predicate);
        }

        public bool Delete(DrugHistory _T)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                dbContext.Dispose();
            }
        }
    }
}
